#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>

using namespace std;
using PII = pair<int, int>;

const int N = 1010, INF = 0x3f3f3f3f;

int n, m, k;
int g[N][N];
int temp[N][N];
int dist[N];
int state[N];

void dijkstra(){
    memset(dist, 0x3f, sizeof dist);
    memset(state, 0, sizeof state);
    priority_queue<PII, vector<PII>, greater<PII>> que;
    dist[1] = 0;
    que.push({dist[1], 1});

    while(que.size()){
        PII te = que.top();
        que.pop();

        int ver = te.second, dis = te.first;
        if(state[ver]) continue;

        state[ver] = true;

        for (int i = 1; i <= n; i ++){
            if(temp[ver][i] != INF){
                if(dist[i] > dist[ver] + temp[ver][i]){
                    dist[i] = dist[ver] + temp[ver][i];
                    que.push({dist[i], i});
                }
            }
        }
    }
}

bool check(int up){
    //100 0000
    memset(temp, 0x3f, sizeof temp);
    for (int i = 1; i <= n; i ++){
        for (int j = 1; j <= n; j ++){
            if(g[i][j] == INF){
                temp[i][j] = INF;
            }else{
                if(g[i][j] > up){
                    temp[i][j] = 1;
                }else{
                    temp[i][j] = 0;
                }
            }
        }
    }

    dijkstra();

    if(dist[n] > k){
        return false;
    }else{
        return true;
    }
}

int solve(){
    int l = 0, r = 1000001;
    while(l < r){
        int mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        }else{
            l = mid + 1;
        }
    }

    return l;
}

int main()
{
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    memset(g, 0x3f, sizeof g);

    scanf("%d%d%d", &n, &m, &k);
    for (int i = 0; i < m; i ++){
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        g[a][b] = c, g[b][a] = c;
    }

    int t = solve();
    if(t == 1000001){
        printf("-1\n");
    }else{
        printf("%d", t);
    }
    return 0;
}